

function changeDisable(obj){
		var param = {
			id:$(obj).attr("dataId"),
			diseaseName:$(obj).attr("title"),
			disable:$(obj).val()
		};
		API.changeDisable(param,function(res) {
			if (res.code == '0') {
			}else{
				location.reload();
				alert(res.desc);
			}
		});
}

function typeClick(obj) {
	var v3 = $("#checkFlag").val();
	if($(obj).attr("title") == '5'){
		v3 = '1'
	}
	var hrefStr = "/icd/disease_hospital_list.htm?checkFlag=" + v3  + "&type=";
	if($(obj).attr("title")) {
		hrefStr += $(obj).attr("title");
	}
	
	location.href = hrefStr;
}

function checkFlagClick(obj) {
	var v3 = $("#type").val();
	var hrefStr = "/icd/disease_hospital_list.htm?type=" + v3  + "&checkFlag=";
	if($(obj).attr("title")) {
		hrefStr += $(obj).attr("title");
	}
	location.href = hrefStr;
}

function submitPage(obj){
		var formData = $('form').serialize();
		API.submitPageDiseaseCheckFlag(formData, function(res) {
			UTIL.releaseButton(obj);
			if (res.code == '0') {
				window.location.reload();
				UTIL.releaseButton(obj);
				return true;
			} else {
				alert(res.desc);
			}
		});
}

function elementExport(obj) {
	if(UTIL.checkButton(obj)) {
		var param = "&chapterSequence="+getFlagByType("chapterSequence")+
		"&chapterCode="+getFlagByType("chapterCode")+
		"&chapterName="+getFlagByType("chapterName")+
		"&sectionCode="+getFlagByType("sectionCode")+
		"&sectionName="+getFlagByType("sectionName")+
		"&gpCode="+getFlagByType("gpCode")+
		"&gpAccessoryCode="+getFlagByType("gpAccessoryCode")+
		"&gpName="+getFlagByType("gpName")+
		"&suborderCode="+getFlagByType("suborderCode")+
		"&suborderAccessoryCode="+getFlagByType("suborderAccessoryCode")+
		"&suborderName="+getFlagByType("suborderName");
		window.location.href="/icd/disease_hospital_export.do?"+param;
		UTIL.releaseButton(obj);
	}
}

function getFlagByType(type){
	if($("#"+type).prop("checked")){
		return 1;
	}else{
		return 0;
	}
}
function diseaseImport(obj) {
	$("#file").click();
}
//$("#file").change(function(){
//	$("#Import").val("导入中");
//	var url="/icd/disease_hospital_import.do";
//	importFile("#file",url,null);
//});


//导入失败弹窗
function importfailed(data) {  
	 $("#alertWarn").empty();
		$("#alertWarn").append(data.desc);	
		$("#importfailed").show();	
	$("#importfailed").dialog({
		autoOpen: true,
		height: 400,
		width: 600,
		modal: true,
		buttons: {
			确定: function() {
				$(this).dialog( "close" );
			}
		},
		close: function() {
			$("#std").val("").removeClass( "ui-state-error" );
		}
	}); 
}

$("#file").change(fileChange);
function fileChange(){
	$("#importButton").val("导入中");
	var file = $("#file").val();

	if(file) {
		var strFileName=file.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1");  //正则表达式获取文件名，不带后缀
		var FileExt=file.replace(/.+\./,"");   //正则表达式获取后缀
				
		// 后缀只能是xlsx，其他不处理
		if(FileExt != 'xlsx') {
			alert("请上传xlsx后缀的Excel文件");
			return false;
		}
		
		$.ajaxFileUpload({			
			url: '/icd/disease_hospital_import.do',
			secureuri: false,
			fileElementId: 'file',
			dataType: 'json',
			data: {"property" : strFileName},
			success: function(data) {
				$("#importButton").val("导入完成");
				$("#file").after($("#file").clone().val(""));
				$("#file").remove();
				$("#file").change(fileChange);
				if(data.code == '0') {
					alert("导入成功！");
					getList();
				} else {
					importfailed(data);			
				}
			}
		});
	}
}

function submitServer(obj) {
	if(confirm("确认要提交吗？")) {
		if(UTIL.checkButton(obj)) {
			API.icdCodeSubmitServer(function(res) {
				if (res.code == '0') {
					alert("提交成功！");
				} else {
					alert("提交失败！");
				}
				UTIL.releaseButton(obj);
			});
		}
	}
}

function selectType(obj,type){
	var checkFlag = false;
	if($(obj).prop("checked")) {
		checkFlag = true;
	}else{
		checkFlag = false;
	}
	
	if(checkFlag){
		// 这个class下的所有字段都展示
		$("."+type).show();
		
	}else{
		// 这个class下的所有字段都隐藏
		$("."+type).hide();
	}
}